<?php
/*
// OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
// all the essential functionalities required for any enterprise.
// Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com

// OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
// the GNU General Public License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.

// OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along with this program;
// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA  02110-1301, USA
*/

require_once ROOT_PATH . '/lib/confs/Conf.php';
require_once ROOT_PATH . '/lib/dao/DMLFunctions.php';
require_once ROOT_PATH . '/lib/dao/SQLQBuilder.php';
require_once ROOT_PATH . '/lib/common/CommonFunctions.php';

class EmpGoodsRecord {

	var $Id;
	var $EmpId;
	var $Num;
	var $Content;
	var $Addtime;

	function EmpGoodsRecord() {
	}

	function setId($Id) {
		$this->Id = $Id;
	}

	function setEmpId($EmpId) {
		$this->EmpId = $EmpId;
	}

	function setNum($Num) {
		$this->Num = $Num;
	}

	function setContent($Content) {
		$this->Content = $Content;
	}

	function setAddtime($Addtime) {
		$this->Addtime = $Addtime;
	}

	function getId() {
		return $this->Id;
	}

	function getEmpId() {
		return $this->EmpId;
	}

	function getNum() {
		return $this->Num;
	}

	function getContent() {
		return $this->Content;
	}

	function getAddtime() {
		return $this->Addtime;
	}

	function getListofEmpGoodsRecord($page,$str,$mode,$getArr="") {

		$tableName = 'HS_HR_EMP_GOODSRECORD';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->field = 'EmpId';

		$sqlQString = $sql_builder->selectGoodsRecord($page,$str,0,$getArr);

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		 while ($line = mysql_fetch_array($message2, MYSQL_ASSOC)) {

	    	/*$arrayDispList[$i][0] = $line[0];
	    	$arrayDispList[$i][1] = $line[1];
	    	$arrayDispList[$i][2] = $line[2];
	    	$arrayDispList[$i][3] = $line[3];
	    	$arrayDispList[$i][4] = $line[4];*/
	    	$arrayDispList[] = $line;
	    	$i++;
	     }

	     if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;

		}
	}
	

	function getOneGoodsRecord($Id) {


		$sqlQString = "select a.*,b.emp_lastname,b.emp_firstname from hs_hr_emp_goodsrecord a left join hs_hr_employee b on b.emp_number=a.EmpId where a.Id = {$Id}";

		$dbConnection = new DMLFunctions();
		$message = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		$arrayDispList = mysql_fetch_array($message, MYSQL_ASSOC);


	     if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;

		}
	}

	function countEmpGoodsRecord($str,$mode) {

		$tableName = 'HS_HR_EMP_GOODSRECORD';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->field = 'ID';

		$sqlQString = $sql_builder->countEmployee($str,$mode);

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$line = mysql_fetch_array($message2, MYSQL_NUM);

	    	return $line[0];
	}

	function delEmpGoodsRecord($arrList) {

		$tableName = 'HS_HR_EMP_GOODSRECORD';
		$arrFieldList[0] = 'ID';
		$arrFieldList[1] = 'type';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_delete = 'true';
		$sql_builder->arr_delete = $arrFieldList;

		$sqlQString = $sql_builder->deleteRecord($arrList);
		//echo $sqlQString;
		//die();
		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		return $message2;
	}

	function addEmpGoodsRecord($array,$type=1) {

		if($array['Id'] > 0) {
			$sqlQString = "update hs_hr_emp_goodsrecord set EmpId='{$array['EmpId']}',Content='{$array['Content']}' where Id='{$array['Id']}' ";
		} else {
			$sqlQString = "insert into hs_hr_emp_goodsrecord (EmpId,Content,type,Addtime) VALUES ({$array['EmpId']},'{$array['Content']}','{$type}',".time().") ";
		}

		$dbConnection = new DMLFunctions();
		$message = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		return $message;

	}

	function updateEmpGoodsRecord() {

		$arrRecordsList[0] = "'". $this->getId() . "'";
		$arrRecordsList[1] = "'". $this->getEmpId() . "'";
		$arrRecordsList[2] = "'". $this->getNum() . "'";
		$arrRecordsList[3] = $this->getContent();
		$arrRecordsList[4] = "'". $this->getAddtime() . "'";

		$tableName = 'HS_HR_EMP_GOODSRECORD';
		$arrFieldList[0] = 'Id';
		$arrFieldList[1] = 'EmpId';
		$arrFieldList[2] = 'Num';
		$arrFieldList[3] = 'Content';
		$arrFieldList[4] = 'Addtime';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_update = 'true';
		$sql_builder->arr_update = $arrFieldList;
		$sql_builder->arr_updateRecList = $arrRecordsList;

		$sqlQString = $sql_builder->addUpdateRecord1(1);
	//echo  $sqlQString;
		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		return $message2;
	}


	function filterEmpGoodsRecord($getID) {

		$tableName = 'HS_HR_EMP_GOODSRECORD';
		$arrFieldList[0] = 'Id';
		$arrFieldList[1] = 'EmpId';
		$arrFieldList[2] = 'Num';
		$arrFieldList[3] = 'Content';
		$arrFieldList[4] = 'Addtime';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->arr_select = $arrFieldList;

		$sqlQString = $sql_builder->selectOneRecordFiltered($getID,1);

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		 while ($line = mysql_fetch_array($message2, MYSQL_NUM)) {

			for($c=0;count($arrFieldList)>$c;$c++)
			   $arrayDispList[$i][$c] = $line[$c];

	    	$i++;

	     }

	     if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;
		}
	}

	function getAssEmpGoodsRecord($getID) {

		$this->getID = $getID;

		$tableName = 'HS_HR_EMP_GOODSRECORD';
		$arrFieldList[0] = 'Id';
		$arrFieldList[1] = 'EmpId';
		$arrFieldList[2] = 'Num';
		$arrFieldList[3] = 'Content';
		$arrFieldList[4] = 'Addtime';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->arr_select = $arrFieldList;

		$sqlQString = $sql_builder->selectOneRecordFiltered($this->getID);

		//echo $sqlQString;
		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		 while ($line = mysql_fetch_array($message2, MYSQL_NUM)) {

			for($c=0;count($arrFieldList)>$c;$c++)
			   $arrayDispList[$i][$c] = $line[$c];

	    	$i++;

	     }

	     if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;
		}
	}

	function getUnAssEmpGoodsRecord($id) {

		$sql_builder = new SQLQBuilder();
		$tableName = 'HS_HR_EMP_GOODSRECORD';
		$arrFieldList[0] = 'Id';
		$arrFieldList[1] = 'EmpId';
		$arrFieldList[2] = 'Content';

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->arr_select = $arrFieldList;
		$sql_builder->field = 'EmpId';
		$sql_builder->table2_name = 'hs_hr_employee';

		$arr[0][0]='Id';
		$arr[0][1]=$id;
		$sqlQString = $sql_builder->selectFilter($arr, 1, 1);

		//echo $sqlQString;
		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		 while ($line = mysql_fetch_array($message2, MYSQL_NUM)) {

	    	$arrayDispList[$i][0] = $line[0];
	    	$arrayDispList[$i][1] = $line[1];
	    	$arrayDispList[$i][2] = $line[2];
	    	$i++;
	     }

	     if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;
		}
	}

}
?>